package com.wty.cmims.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wty.cmims.pojo.Code;
import com.wty.cmims.pojo.HealthInstitution;
import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.HealthInstitutionService;
import com.wty.cmims.mapper.HealthInstitutionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author wty
* @description 针对表【health_institution】的数据库操作Service实现
* @createDate 2024-11-03 20:22:34
*/
@Service
public class HealthInstitutionServiceImpl extends ServiceImpl<HealthInstitutionMapper, HealthInstitution>
    implements HealthInstitutionService{
    @Autowired
    private HealthInstitutionMapper healthInstitutionMapper;
    @Override
    public ResponseResult<Map<String, Object>> healthInstitutionFind(Map<String,Object> paramsMap) {
        ResponseResult<Map<String, Object>> responseResult = new ResponseResult<>();
        // 分页
        if (paramsMap.get("currentPage") != null && !paramsMap.get("currentPage").equals("") &&
                paramsMap.get("pageSize") != null && !paramsMap.get("pageSize").equals("")
        ){
            Integer pageSize = (Integer) paramsMap.get("pageSize");
            paramsMap.put("start", ((Integer) paramsMap.get("currentPage") - 1) * pageSize);
            responseResult.setPageSize(pageSize);
        }

        List<Map<String, Object>> healthInstitutions = healthInstitutionMapper.findHealthInstitutions(paramsMap);
        Integer total = healthInstitutionMapper.findHealthInstitutionsNum(paramsMap);
        if (healthInstitutions != null) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("查询医疗机构信息成功");
            responseResult.setDatas(healthInstitutions);
            responseResult.setTotal(total);
            responseResult.setCurrentPage((Integer) paramsMap.get("currentPage"));
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("查询医疗机构信息失败");
        }
        return responseResult;
    }

    @Override
    public ResponseResult<HealthInstitution> healthInstitutionFindById(Integer id) {
        ResponseResult<HealthInstitution> responseResult = new ResponseResult<>();
        HealthInstitution healthInstitution = healthInstitutionMapper.selectById(id);
        if (healthInstitution != null) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("查询该医疗机构信息成功");
            responseResult.setData(healthInstitution);
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("查询该医疗机构信息失败");
        }
        return responseResult;
    }
}




